package com.example.content

import androidx.multidex.MultiDexApplication
import com.example.content.manager.ActivityMgr
import com.example.content.manager.IMMgr
import com.example.content.repository.ApiService
import com.example.content.repository.oprators.HeaderInterceptor
import com.example.content.repository.oprators.TokenAuthenticator
import com.example.core.Core
import com.example.core.extensions.notNullSingleValue
import com.example.core.network.HttpClient
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig
import com.xuexiang.xui.XUI
import com.xuexiang.xutil.XUtil
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager

/**
 * Created by zhudongao
 * Desc
 * Date 2020/9/19
 */
class App : MultiDexApplication() {


    init {
        val fileProvider = "com.umeng.soexample.fileprovider";
        PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
        PlatformConfig.setWXFileProvider(fileProvider);
        //企业微信设置
        PlatformConfig.setWXWork(
            "wwac6ffb259ff6f66a",
            "EU1LRsWC5uWn6KUuYOiWUpkoH45eOA0yH-ngL8579zs",
            "1000002",
            "wwauthac6ffb259ff6f66a000002"
        );
        PlatformConfig.setWXWorkFileProvider(fileProvider);

        PlatformConfig.setSinaWeibo(
            "3921700954",
            "04b48b094faeb16683c32669824ebdad",
            "http://sns.whalecloud.com"
        );
        PlatformConfig.setSinaFileProvider(fileProvider);
        PlatformConfig.setQQZone("101830139", "5d63ae8858f1caab67715ccd6c18d7a5");
        PlatformConfig.setQQFileProvider(fileProvider);
    }

    override fun onCreate() {
        super.onCreate()
        appContext = this
//        SAK.init(this, null)
        XUI.init(this)
        Core.init(this)
        IMMgr.init(this)
        XUtil.init(this)
        registerActivityLifecycleCallbacks(ActivityMgr)

        HttpClient.init(this, ApiService.BASE_URL)
            .authenticator(TokenAuthenticator())
            .addInterceptor(HeaderInterceptor())
            .build(true)
        //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口
        UMConfigure.init(
            this, "59892f08310c9307b60023d0", "Umeng", UMConfigure.DEVICE_TYPE_PHONE,
            "669c30a9584623e70e8cd01b0381dcb4"
        )

        PlayerFactory.setPlayManager(Exo2PlayerManager::class.java)
    }

    companion object {
        var appContext by notNullSingleValue<App>()
    }
}